home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / ksyntaxhighlighter.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  5.5 KB  |  185 lines

  1. /*
  2.  ksyntaxhighlighter.cpp
  3.  
  4.  Copyright (c) 2003 Trolltech AS
  5.  Copyright (c) 2003 Scott Wheeler <wheeler@kde.org>
  6.  
  7.  This file is part of the KDE libraries
  8.  
  9.  This library is free software; you can redistribute it and/or
  10.  modify it under the terms of the GNU Library General Public
  11.  License version 2 as published by the Free Software Foundation.
  12.  
  13.  This library is distributed in the hope that it will be useful,
  14.  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  Library General Public License for more details.
  17.  
  18.  You should have received a copy of the GNU Library General Public License
  19.  along with this library; see the file COPYING.LIB.  If not, write to
  20.  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21.  Boston, MA 02110-1301, USA.
  22. */
  23.  
  24. #ifndef KSYNTAXHIGHLIGHTER_H
  25. #define KSYNTAXHIGHLIGHTER_H
  26.  
  27. #include <qtextedit.h>
  28. #include <qsyntaxhighlighter.h>
  29. #include <qcolor.h>
  30. #include <qstringlist.h>
  31.  
  32. #include <kdelibs_export.h>
  33.  
  34. class QAccel;
  35. class QTimer;
  36. class KSpell;
  37. class KSpellConfig;
  38.  
  39. /**
  40.  * \brief Syntax sensitive text highlighter
  41.  */
  42. class KDEUI_EXPORT KSyntaxHighlighter : public QSyntaxHighlighter
  43. {
  44. public:
  45.     enum SyntaxMode {
  46.     PlainTextMode,
  47.     RichTextMode
  48.     };
  49.     KSyntaxHighlighter( QTextEdit *textEdit,
  50.              bool colorQuoting = false,
  51.              const QColor& QuoteColor0 = black,
  52.              const QColor& QuoteColor1 = QColor( 0x00, 0x80, 0x00 ),
  53.              const QColor& QuoteColor2 = QColor( 0x00, 0x80, 0x00 ),
  54.              const QColor& QuoteColor3 = QColor( 0x00, 0x80, 0x00 ),
  55.              SyntaxMode mode = PlainTextMode );
  56.     ~KSyntaxHighlighter();
  57.  
  58.     int highlightParagraph( const QString& text, int endStateOfLastPara );
  59.  
  60. private:
  61.     class KSyntaxHighlighterPrivate;
  62.     KSyntaxHighlighterPrivate *d;
  63. };
  64.  
  65. class KDEUI_EXPORT KSpellingHighlighter : public KSyntaxHighlighter
  66. {
  67. public:
  68.     KSpellingHighlighter( QTextEdit *textEdit,
  69.               const QColor& spellColor = red,
  70.               bool colorQuoting = false,
  71.               const QColor& QuoteColor0 = black,
  72.               const QColor& QuoteColor1 = QColor( 0x00, 0x80, 0x00 ),
  73.               const QColor& QuoteColor2 = QColor( 0x00, 0x80, 0x00 ),
  74.               const QColor& QuoteColor3 = QColor( 0x00, 0x80, 0x00 ) );
  75.     ~KSpellingHighlighter();
  76.  
  77.     virtual int highlightParagraph( const QString &text,
  78.                     int endStateOfLastPara );
  79.     virtual bool isMisspelled( const QString& word ) = 0;
  80.     bool intraWordEditing() const;
  81.     void setIntraWordEditing( bool editing );
  82.     static QStringList personalWords();
  83.  
  84. private:
  85.     void flushCurrentWord();
  86.  
  87.     class KSpellingHighlighterPrivate;
  88.     KSpellingHighlighterPrivate *d;
  89. };
  90.  
  91. /**
  92.  * \brief Dictionary sensitive text highlighter
  93.  */
  94. class KDEUI_EXPORT KDictSpellingHighlighter : public QObject, public KSpellingHighlighter
  95. {
  96. Q_OBJECT
  97.  
  98. public:
  99.     KDictSpellingHighlighter( QTextEdit *textEdit,
  100.                   bool spellCheckingActive = true,
  101.                   bool autoEnable = true,
  102.                   const QColor& spellColor = red,
  103.                   bool colorQuoting = false,
  104.                   const QColor& QuoteColor0 = black,
  105.                   const QColor& QuoteColor1 = QColor( 0x00, 0x80, 0x00 ),
  106.                   const QColor& QuoteColor2 = QColor( 0x00, 0x70, 0x00 ),
  107.                   const QColor& QuoteColor3 = QColor( 0x00, 0x60, 0x00 ),
  108.                               KSpellConfig *spellConfig = 0 );
  109.     ~KDictSpellingHighlighter();
  110.  
  111.     virtual bool isMisspelled( const QString &word );
  112.     static void dictionaryChanged();
  113.     void restartBackgroundSpellCheck();
  114.  
  115.     /**
  116.      * @short Enable/Disable spell checking.
  117.      *
  118.      * If @p active is true then spell checking is enabled; otherwise it
  119.      * is disabled. Note that you have to disable automatic (de)activation
  120.      * with @ref setAutomatic() before you change the state of spell checking
  121.      * if you want to persistently enable/disable spell checking.
  122.      *
  123.      * @param active if true, then spell checking is enabled
  124.      *
  125.      * @see isActive(), setAutomatic()
  126.      */
  127.     void setActive( bool active );
  128.  
  129.     /**
  130.      * Returns the state of spell checking.
  131.      *
  132.      * @return true if spell checking is active
  133.      *
  134.      * @see setActive()
  135.      */
  136.     bool isActive() const;
  137.  
  138.     /**
  139.      * @short En-/Disable automatic (de)activation in case of too many errors.
  140.      *
  141.      * If @p automatic is true then spell checking will be deactivated if
  142.      * too many words were mispelled and spell checking will be activated
  143.      * again if the amount of mispelled words drop below a certain threshold.
  144.      *
  145.      * @param automatic if true, then automatic (de)activation is enabled
  146.      *
  147.      * @see automatic()
  148.      */
  149.     void setAutomatic( bool automatic );
  150.  
  151.     /**
  152.      * Returns the state of automatic (de)activation.
  153.      *
  154.      * @return true if automatic (de)activation is enabled
  155.      *
  156.      * @see setAutomatic()
  157.      */
  158.     bool automatic() const;
  159.  
  160. signals:
  161.     void activeChanged(const QString &);
  162.     void newSuggestions(const QString& originalword, const QStringList& suggestions,
  163.                         unsigned int pos);
  164.  
  165. protected:
  166.     QString spellKey();
  167.     bool eventFilter(QObject *o, QEvent *e);
  168.  
  169. protected slots:
  170.     void slotMisspelling( const QString &originalWord, const QStringList &suggestions, unsigned int pos );
  171.     void slotCorrected( const QString &originalWord, const QString &, unsigned int );
  172.     void slotRehighlight();
  173.     void slotDictionaryChanged();
  174.     void slotSpellReady( KSpell *spell );
  175.     void slotAutoDetection();
  176.     void slotLocalSpellConfigChanged();
  177.     void slotKSpellNotResponding();
  178.  
  179. private:
  180.     class KDictSpellingHighlighterPrivate;
  181.     KDictSpellingHighlighterPrivate *d;
  182. };
  183.  
  184. #endif
  185.